﻿// --------------------------------------------------------------------------------------------------------------------- 
// <copyright file="T4PropertyCollectorTests.cs" company="Microsoft.Blueprints.Contrib Team">
//   (C) Microsoft.Blueprints.Contrib Team 2009
// </copyright>
// <summary>
//   Defines the T4PropertyCollectorTests type.
// </summary>
// ---------------------------------------------------------------------------------------------------------------------
namespace Microsoft.Blueprints.Contrib.Tests
{
    #region Using Directives

    using MbUnit.Framework;
    using T4;

    using Utils;

    #endregion

    /// <summary>
    /// Test to ensure that the T4PropertyCollector works correctly.
    /// </summary>
    [TestFixture]
    public class T4PropertyCollectorTests
    {
        /// <summary>
        /// T4 Template used for creating a web application installer.
        /// </summary>
        private const string Template01 = "Microsoft.Blueprints.Contrib.Tests.Templates.Template01.t4";
        
        /// <summary>
        /// T4 Templated used to hold Build Properties
        /// </summary>
        private const string Template02 = "Microsoft.Blueprints.Contrib.Tests.Templates.Template02.t4";

        /// <summary>
        /// Ensure that T4PropertyCollector can collect the correct number of properties from a single template
        /// </summary>
        [Test]
        public void T4PropertyCollector_Can_Collect_Properties_From_One_Template()
        {
            string templateFile01 = T4TemplateResourceExtractor.CreateTemporaryFileFromResource(Template01);

            var properties = T4PropertyCollector.Start()
                                                    .AddTemplate(templateFile01)
                                                    .Collect()
                                                .Finish();

            Assert.AreEqual(properties.Count, 6);
        }

        /// <summary>
        /// Ensure that T4PropertyCollector can collect the correct number of properties from a multiple templates
        /// </summary>
        [Test]
        public void T4PropertyCollector_Can_Collect_Properties_From_Two_Templates()
        {
            string templateFile01 = T4TemplateResourceExtractor.CreateTemporaryFileFromResource(Template01);
            string templateFile02 = T4TemplateResourceExtractor.CreateTemporaryFileFromResource(Template02);

            var properties = T4PropertyCollector.Start()
                                                    .AddTemplate(templateFile01)
                                                    .AddTemplate(templateFile02)
                                                    .Collect()
                                                .Finish();

            // templateFile02 only introduces 1 new T4 property
            Assert.AreEqual(properties.Count, 7);
        }
    }
}
